package com.xry.controller;

import com.xry.bean.Role;
import com.xry.service.RoleService;
import com.xry.util.Page;
import com.xry.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin//允许跨域
@RequestMapping("/role")
public class RoleController {
    @Autowired
    RoleService roleService;

    @PostMapping
    public Result add(@RequestBody Role role){
        Object obj=roleService.add(role);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Role role){
        Object obj=roleService.edit(role);
        return Result.success(obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id){
        Object obj=roleService.del(id);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id")Integer id){
        Object obj=roleService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all( Role role){
        Object obj=roleService.all(role);
        return Result.success(obj);
    }
    @GetMapping("page")
    public Result page(Page page, Role role){
        //查询一共有多少条数据
        //查询当前页要显示的数据
        //将当前页封装到page对象中
        roleService.page(page,role);
        //返回page对象
        return Result.success(page);
    }

}
